package clustering;

import graphNew.MainGraph;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import main.Translating;

import org.jgrapht.graph.DefaultWeightedEdge;

import components.Operator;

//this class represents the Edge Betweeness algorithm
public class EdgeBetwennessCluster implements ClusteringIfc {
	
	private int numOfEdgesToRemove;
	private Set<VerticesSet> clusterSet;
	
	
	public EdgeBetwennessCluster(int numEdges){
		this.numOfEdgesToRemove = numEdges;
		this.clusterSet = new HashSet<VerticesSet> ();
	}
	
	@Override
	//gets the main graph and the amount of desirable clusters
	//returns set of clusters (represented as vertices sets)
	public Set<VerticesSet> cluster(MainGraph graph, int numClusters) {
		edu.uci.ics.jung.graph.Graph<Operator, DefaultWeightedEdge> jungGraph = Translating.ourGraphToJungGraph(graph);
		
		edu.uci.ics.jung.algorithms.cluster.EdgeBetweennessClusterer<Operator, DefaultWeightedEdge> ec =
			new edu.uci.ics.jung.algorithms.cluster.EdgeBetweennessClusterer <Operator, DefaultWeightedEdge>(this.numOfEdgesToRemove);
		
		Collection<Set<Operator>> clusteredSet = ec.transform(jungGraph);
		
		for (Set<Operator> vertexSet : clusteredSet){
			VerticesSet vSet = new VerticesSet(vertexSet);
			this.clusterSet.add(vSet);
		}
		
		return clusterSet;
	}

}
